package com.weilian.ordering.util;

import java.lang.ref.WeakReference;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;

public class Util {
	public static WeakReference<Bitmap> loadBitmapFromSDCard(String path) {
		// CacheManager.checkCache();
		BitmapFactory.Options options = new Options();
//		options.inSampleSize = 3;
		options.inTempStorage = new byte[16 * 1024];
		WeakReference<Bitmap> softReference;
		// Bitmap bitmap = null;
		try {
			// bitmap = BitmapFactory.decodeFile(path, options);
			softReference = new WeakReference<Bitmap>(BitmapFactory.decodeFile(
					path, options));
			CacheManager.add(path, softReference.get());
			return softReference;
		} catch (OutOfMemoryError e) {
			// TODO: handle exception
			CacheManager.clear();
			softReference = new WeakReference<Bitmap>(BitmapFactory.decodeFile(
					path, options));
			CacheManager.add(path, softReference.get());
			return softReference;
		}
	}

}
